package view;

import java.awt.Color;
import java.awt.Dimension;
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.Map;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.table.DefaultTableModel;

import net.miginfocom.swing.MigLayout;

/**
 * Panel to list the emails in a particular folder
 * @author MUSAB
 *
 */
public class ListingView extends JPanel {
	
	// Toolbar buttons
	private JButton deleteBtn, moveBtn;
	
	// The emails list
	private DefaultTableModel emails;
	
	// The emails  table
	private JTable emailsTable;
	
	/**
	 * Constructor
	 * @param migLayout
	 */
	public ListingView(MigLayout migLayout){
		
		// Calling super constructor
		super(migLayout);
		
		/**
		 * Creating the toolbar
		 */
		deleteBtn = new JButton("Delete");
		moveBtn = new JButton("Move");
		JLabel folderNameLabel = new JLabel("Folder");
		JPanel toolbar = new JPanel(new MigLayout("fillx", ""));
		toolbar.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.LIGHT_GRAY));
		toolbar.add(folderNameLabel);
		toolbar.add(moveBtn, "push, al right");
		toolbar.add(deleteBtn, "al right");
		this.add(toolbar, "wrap, growx");
		
		
		/**
		 * Creating the email list table
		 */
		String[] columnNames = {
				"No",
                "From",
                "To",
                "Date/time",
                "Subject"
		};

		emails = new DefaultTableModel();
		emails.setColumnIdentifiers(columnNames);
		
		// Some temp static data
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		emails.addRow(new Object[]{"sdfs","sdg","hhh","sdsdfds"});
		
		// Uneditable table
		emailsTable = new JTable(emails){
			@Override
			public boolean isCellEditable(int row, int column){  
			    return false;  
			}  
		};
		JScrollPane emailsScrollPane = new JScrollPane(emailsTable);
		this.add(emailsScrollPane, "growx, height 100::200"); // max height of listing pane
	}

	/**
	 * Returns the move button
	 * @return
	 */
	public JButton getMoveBtn() {
		return moveBtn;
	}

	/**
	 * Returns the delete button
	 * @return
	 */
	public JButton getDeleteBtn() {
		return deleteBtn;
	}	
	
	/**
	 * Returns the Emails JTable
	 * @return
	 */
	public JTable getEmailsTable(){
		return emailsTable;
	}

}
